import java.util.Scanner;

/**
 * 数据校验类
 */
public class TelNoteRegex
{
    /**
     * 菜单验证
     * @param min
     * @param max
     * @return
     */
    public int menuItemValidate(int min, int max)
    {
        //定义验证菜单项的正则表达式
        String regex = "[1-9]";
    
        Scanner scan = new Scanner(System.in);
        while(true)
        {
            System.out.println("请输入正确的数字，最小值为：" + min + "最大值为：" + max);
            
            String inPut = scan.nextLine();
            if(inPut.matches(regex))
            {
                int inPutNum = Integer.parseInt(inPut);
                if(inPutNum >= min && inPutNum <= max)
                    return inPutNum;
                else
                    System.out.println("输入的数字最小值为：" + min + "最大值为：" + max);
            }
            else
                System.out.println("输入数字错误，请检查...");
        }
    }
    
    /**
     * 姓名验证
     * @return
     */
    public String nameValidate()
    {
        String regex = "[a-zA-Z]{1,10}";
    
        Scanner scan = new Scanner(System.in);
        
        while(true)
        {
            System.out.println("请输入姓名：格式为1-10之间的大小写字母");
            
            String inPut = scan.nextLine();
    
            if(inPut.matches(regex))
                return inPut;
            else
                System.out.println("您输入的姓名有误，请重新输入！");
        }
    }
    
    public String ageValidate()
    {
        String regex = "[1-9]{1}[0-9]{1,2}";
    
        Scanner scan = new Scanner(System.in);
        
        while(true)
        {
            System.out.println("请输入年龄：不以0开头的两到三位数字");
            
            String inPut = scan.nextLine();
            if(inPut.matches(regex))
                return inPut;
            else
                System.out.println("您输入的年龄不合法，请重新输入！");
        }
    }
    
    public String sexValidate()
    {
        String regex = "[M|F]";
    
        Scanner scan = new Scanner(System.in);
        
        while(true)
        {
            System.out.println("请输入性别：男为M，女为F");
            
            String inPut = scan.nextLine();
    
            if(inPut.matches(regex))
                return inPut;
            
            else
                System.out.println("您输入的性别不合法，请重新输入！");
        }
    }
    
    public String telNumValidate()
    {
        String regex = "(\\d{3,4})-(\\d{7,8})|([1]{1})(\\d{10})";
    
        Scanner scan = new Scanner(System.in);
        
        while(true)
        {
            System.out.println("请输入11位数字手机号或7/8位座机号");
            
            String inPut = scan.nextLine();
    
            if(inPut.matches(regex))
                return inPut;
            else
                System.out.println("您输入的手机号或座机号不合法，请重新输入！");
        }
    }
    
    public String AddressValidate()
    {
        String regex = "\\w+";
    
        Scanner scan = new Scanner(System.in);
    
        while(true)
        {
            System.out.println("请输入地址：格式为字母或数字");
            
            String inPut = scan.nextLine();
    
            if(inPut.matches(regex))
                return inPut;
            else
                System.out.println("您输入的地址有误，请重新输入！");
        }
    }
}
